<div class="selenium-notes">
<h1>Selenium Java Dependency</h1>
<p>Selenium Java Dependency is the Maven dependency that allows a Java project to use Selenium WebDriver APIs for browser automation. When Selenium is added as a dependency in the project's <strong>pom.xml</strong> file, Maven downloads the required Selenium libraries and their required transitive dependencies and makes them available to the Java automation project.</p>
<p>For modern Selenium Java projects, the commonly used Maven artifact is <strong>org.seleniumhq.selenium:selenium-java</strong>. Using Maven makes Selenium dependency management easier because libraries, versions, transitive dependencies, builds, and test execution can be managed from the project configuration.</p>
<p><strong>Course Resource:</strong> <a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">Selenium Training</a> | <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">Register for Course Demo</a></p>
<hr>
<h2>1. What is Selenium Java Dependency?</h2>
<p>A Selenium Java dependency is a library declaration that tells Maven that the Java project requires Selenium WebDriver. Instead of downloading Selenium JAR files manually, the dependency is declared in <strong>pom.xml</strong>.</p>
<pre><code><dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>YOUR_SELENIUM_VERSION</version>
</dependency></code></pre>
<p>After Maven resolves this dependency, Selenium classes such as <strong>WebDriver</strong>, <strong>ChromeDriver</strong>, <strong>FirefoxDriver</strong>, <strong>By</strong>, <strong>WebElement</strong>, <strong>WebDriverWait</strong>, and other Selenium APIs become available to the project.</p>
<hr>
<h2>2. Why is Selenium Dependency Required?</h2>
<p>Java itself does not contain Selenium WebDriver classes. Selenium provides the APIs required to automate web browsers.</p>
<p>Without Selenium libraries, Java code such as the following cannot compile:</p>
<pre><code>WebDriver driver = new ChromeDriver();</code></pre>
<p>After adding the Selenium dependency, the project can import and use Selenium classes.</p>
<hr>
<h2>3. Selenium Java Dependency Coordinates</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Element</th><th>Value</th><th>Purpose</th></tr>
<tr><td>groupId</td><td>org.seleniumhq.selenium</td><td>Identifies the Selenium organization or dependency group.</td></tr>
<tr><td>artifactId</td><td>selenium-java</td><td>Identifies the Selenium Java artifact.</td></tr>
<tr><td>version</td><td>Selected Selenium version</td><td>Specifies the Selenium release used by the project.</td></tr>
</table>
<hr>
<h2>4. Basic Selenium Java Maven Dependency</h2>
<pre><code><dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>YOUR_SELENIUM_VERSION</version>
</dependency></code></pre>
<p>The version should be selected according to the requirements and compatibility of the automation project.</p>
<hr>
<h2>5. Understanding groupId</h2>
<p>The <strong>groupId</strong> identifies the organization or logical group responsible for an artifact.</p>
<pre><code><groupId>org.seleniumhq.selenium</groupId></code></pre>
<p>For the Selenium Java artifact, the groupId is:</p>
<pre><code>org.seleniumhq.selenium</code></pre>
<hr>
<h2>6. Understanding artifactId</h2>
<p>The <strong>artifactId</strong> identifies the specific Maven artifact.</p>
<pre><code><artifactId>selenium-java</artifactId></code></pre>
<p>The commonly used Selenium Java dependency is:</p>
<pre><code>org.seleniumhq.selenium:selenium-java</code></pre>
<hr>
<h2>7. Understanding Version</h2>
<p>The <strong>version</strong> identifies the Selenium release that Maven should use.</p>
<pre><code><version>YOUR_SELENIUM_VERSION</version></code></pre>
<p>Using an explicitly controlled version makes the project more predictable and helps prevent unexpected dependency changes.</p>
<hr>
<h2>8. How Selenium Dependency Works</h2>
<pre><code>pom.xml
|
v
Selenium Dependency
|
v
Maven Repository
|
v
Download Selenium Libraries
|
v
Local Maven Repository
|
v
Project Classpath
|
v
Java Selenium Code
|
v
Browser Automation</code></pre>
<hr>
<h2>9. Maven Repository and Selenium</h2>
<p>Maven obtains dependencies from configured repositories. When a required Selenium artifact is not already available locally, Maven resolves the artifact and downloads it into the local Maven repository.</p>
<p>Once downloaded, Maven can reuse the cached dependency for future builds.</p>
<hr>
<h2>10. Local Maven Repository</h2>
<p>Maven maintains a local repository where downloaded dependencies are cached.</p>
<p>On many systems, the repository is located at:</p>
<pre><code>~/.m2/repository</code></pre>
<p>On Windows, it is commonly located at:</p>
<pre><code>C:\Users\USERNAME\.m2\repository</code></pre>
<p>A Selenium artifact may be stored under a structure similar to:</p>
<pre><code>.m2/
└── repository/
└── org/
└── seleniumhq/
└── selenium/
└── selenium-java/</code></pre>
<hr>
<h2>11. What Happens After Adding the Dependency?</h2>
<p>When the Selenium dependency is added to <strong>pom.xml</strong>, Maven reads the dependency coordinates and resolves the required artifacts.</p>
<pre><code>Add Dependency
|
v
Save pom.xml
|
v
Maven Reads POM
|
v
Resolve Selenium Artifact
|
v
Resolve Required Dependencies
|
v
Download Missing Artifacts
|
v
Store in Local Repository
|
v
Add to Project Classpath
|
v
Use Selenium APIs</code></pre>
<hr>
<h2>12. Selenium Java Dependency and JAR Files</h2>
<p>Before dependency management tools became common in Java projects, developers often downloaded JAR files manually and added them to the project classpath.</p>
<p>Maven reduces this manual work. The developer declares the dependency once in <strong>pom.xml</strong>, and Maven handles dependency resolution.</p>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Manual JAR Approach</th><th>Maven Dependency Approach</th></tr>
<tr><td>Download JAR files manually.</td><td>Declare dependency in pom.xml.</td></tr>
<tr><td>Configure classpath manually.</td><td>Maven manages dependencies.</td></tr>
<tr><td>Track versions manually.</td><td>Version is declared in POM.</td></tr>
<tr><td>Update JAR files manually.</td><td>Change dependency version.</td></tr>
<tr><td>Dependency relationships are harder to maintain.</td><td>Maven resolves transitive dependencies.</td></tr>
</table>
<hr>
<h2>13. Selenium Dependency in a Complete pom.xml</h2>
<pre><code><project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>selenium-automation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<selenium.version>YOUR_SELENIUM_VERSION</selenium.version>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
</project></code></pre>
<hr>
<h2>14. Using a Maven Property for Selenium Version</h2>
<p>Instead of writing the Selenium version directly inside the dependency, a Maven property can be used.</p>
<pre><code><properties>
<selenium.version>YOUR_SELENIUM_VERSION</selenium.version>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies></code></pre>
<p>This approach makes version management easier because the version can be changed in one location.</p>
<hr>
<h2>15. Selenium Dependency with TestNG</h2>
<p>Selenium WebDriver is commonly combined with TestNG for creating structured automated test cases.</p>
<pre><code><dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>YOUR_SELENIUM_VERSION</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>YOUR_TESTNG_VERSION</version>
<scope>test</scope>
</dependency>
</dependencies></code></pre>
<hr>
<h2>16. Selenium Dependency with JUnit</h2>
<p>JUnit can also be used as the test framework for a Selenium Maven project.</p>
<pre><code><dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>YOUR_SELENIUM_VERSION</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>YOUR_JUNIT_VERSION</version>
<scope>test</scope>
</dependency></code></pre>
<hr>
<h2>17. Selenium Java Dependency Scope</h2>
<p>Dependency scope determines when a Maven dependency is available during the project lifecycle.</p>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Scope</th><th>Meaning</th><th>Typical Usage</th></tr>
<tr><td>compile</td><td>Available during compilation and runtime.</td><td>Common for framework dependencies.</td></tr>
<tr><td>test</td><td>Available while compiling and running tests.</td><td>Common for test-only libraries.</td></tr>
<tr><td>provided</td><td>Expected to be supplied by the runtime environment.</td><td>Not normally used for Selenium.</td></tr>
<tr><td>runtime</td><td>Required during runtime but not compilation.</td><td>Used for specific runtime libraries.</td></tr>
</table>
<p>The Selenium dependency is commonly declared without a scope when application or framework code directly uses Selenium APIs.</p>
<hr>
<h2>18. Transitive Dependencies</h2>
<p>A transitive dependency is a library that is required by another dependency. Maven can resolve these dependency relationships automatically.</p>
<pre><code>selenium-java
|
+-- Selenium API
|
+-- Browser Driver Components
|
+-- Remote Driver Components
|
+-- Selenium Support
|
+-- Other Required Components</code></pre>
<p>This means a typical project does not need to manually download every Selenium JAR file.</p>
<hr>
<h2>19. selenium-api</h2>
<p><strong>selenium-api</strong> contains core Selenium API classes and interfaces used by Selenium automation code.</p>
<p>Examples include types related to WebDriver, WebElement, capabilities, and other Selenium functionality.</p>
<p>In a standard project, testers generally use the broader <strong>selenium-java</strong> dependency instead of declaring selenium-api separately.</p>
<hr>
<h2>20. Selenium Browser Driver Components</h2>
<p>The Selenium Java distribution provides components required to work with supported browsers. For example, Chrome and Firefox automation can be created using the corresponding WebDriver classes.</p>
<pre><code>WebDriver chromeDriver = new ChromeDriver();
chromeDriver.get("https://example.com");
chromeDriver.quit();</code></pre>
<pre><code>WebDriver firefoxDriver = new FirefoxDriver();
firefoxDriver.get("https://example.com");
firefoxDriver.quit();</code></pre>
<hr>
<h2>21. selenium-remote-driver</h2>
<p>The remote driver component supports remote browser execution and communication with remote Selenium infrastructure such as Selenium Grid.</p>
<pre><code>WebDriver driver = new RemoteWebDriver(
serverUrl,
options
);</code></pre>
<hr>
<h2>22. selenium-support</h2>
<p>The Selenium support component provides additional APIs used for common automation tasks.</p>
<p>For example, explicit waits commonly use:</p>
<pre><code>WebDriverWait
ExpectedConditions</code></pre>
<hr>
<h2>23. Why Use selenium-java Instead of Individual Selenium JARs?</h2>
<p>For a typical Selenium Java automation project, the <strong>selenium-java</strong> dependency simplifies setup because Maven can resolve the Selenium Java client and its required Selenium components.</p>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Approach</th><th>Characteristics</th></tr>
<tr><td>selenium-java</td><td>Convenient dependency for typical Selenium Java projects.</td></tr>
<tr><td>Individual Selenium artifacts</td><td>Useful when a project has a specific modular dependency requirement.</td></tr>
<tr><td>Manual JAR files</td><td>Requires manual downloading and classpath management.</td></tr>
</table>
<hr>
<h2>24. Creating a Selenium Maven Project</h2>
<ol>
<li>Install a compatible JDK.</li>
<li>Install Maven or use Maven Wrapper.</li>
<li>Open IntelliJ IDEA, Eclipse, or another Java IDE.</li>
<li>Create a Maven project.</li>
<li>Configure groupId, artifactId, and version.</li>
<li>Open pom.xml.</li>
<li>Add the Selenium Java dependency.</li>
<li>Reload or synchronize the Maven project.</li>
<li>Create Java Selenium test classes.</li>
<li>Run the tests.</li>
</ol>
<hr>
<h2>25. Maven Selenium Project Structure</h2>
<pre><code>selenium-java-project/
|
|-- pom.xml
|
|-- src/
| |
| |-- main/
| | |-- java/
| | |-- pages/
| | |-- utilities/
| |
| |-- test/
| |-- java/
| |-- tests/
| |-- base/
|
|-- target/</code></pre>
<hr>
<h2>26. First Selenium Java Program</h2>
<p>Once the Selenium dependency has been added, a basic Selenium Java program can be written.</p>
<pre><code>import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstSeleniumTest {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
System.out.println(driver.getTitle());
} finally {
driver.quit();
}
}
}</code></pre>
<hr>
<h2>27. Important Selenium Java Imports</h2>
<p>The Selenium dependency makes Selenium Java packages available to the project.</p>
<pre><code>import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;</code></pre>
<hr>
<h2>28. Selenium Dependency and Locators</h2>
<p>After adding Selenium, locator APIs can be used to identify elements on web pages.</p>
<pre><code>WebElement username =
driver.findElement(By.id("username"));
username.sendKeys("testuser");</code></pre>
<p>Common Selenium locator strategies include:</p>
<ul>
<li>By.id()</li>
<li>By.name()</li>
<li>By.className()</li>
<li>By.tagName()</li>
<li>By.linkText()</li>
<li>By.partialLinkText()</li>
<li>By.cssSelector()</li>
<li>By.xpath()</li>
</ul>
<hr>
<h2>29. Selenium Dependency and WebDriver</h2>
<p><strong>WebDriver</strong> is one of the central Selenium interfaces used to control browsers.</p>
<pre><code>WebDriver driver = new ChromeDriver();</code></pre>
<p>Typical WebDriver operations include:</p>
<pre><code>driver.get("https://example.com");
driver.getTitle();
driver.getCurrentUrl();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();
driver.quit();</code></pre>
<hr>
<h2>30. Selenium Dependency and WebElement</h2>
<p><strong>WebElement</strong> represents an element on a web page.</p>
<pre><code>WebElement searchBox =
driver.findElement(By.id("search"));
searchBox.clear();
searchBox.sendKeys("Selenium");
searchBox.click();</code></pre>
<hr>
<h2>31. Selenium Dependency and Explicit Waits</h2>
<p>The Selenium dependency also allows Selenium wait APIs to be used in Java automation scripts.</p>
<pre><code>WebDriverWait wait =
new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement loginButton = wait.until(
ExpectedConditions.elementToBeClickable(
By.id("login")
)
);
loginButton.click();</code></pre>
<p>Required imports:</p>
<pre><code>import java.time.Duration;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;</code></pre>
<hr>
<h2>32. Selenium Dependency and Page Object Model</h2>
<p>The Selenium Java dependency is commonly used inside Page Object Model classes.</p>
<pre><code>public class LoginPage {
private WebDriver driver;
private By username = By.id("username");
private By password = By.id("password");
private By loginButton = By.id("login");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
public void login(String user, String pass) {
driver.findElement(username).sendKeys(user);
driver.findElement(password).sendKeys(pass);
driver.findElement(loginButton).click();
}
}</code></pre>
<hr>
<h2>33. Selenium Dependency and TestNG</h2>
<p>TestNG can be combined with Selenium to create structured automated test cases.</p>
<pre><code>import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class LoginTest {
@Test
public void loginTest() {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
} finally {
driver.quit();
}
}
}</code></pre>
<hr>
<h2>34. Maven Test Execution</h2>
<p>After adding Selenium and a test framework to the Maven project, tests can be executed using Maven commands.</p>
<pre><code>mvn test</code></pre>
<p>A clean test execution can be performed with:</p>
<pre><code>mvn clean test</code></pre>
<p>The general flow is:</p>
<pre><code>pom.xml
|
v
Resolve Dependencies
|
v
Compile Java Code
|
v
Compile Test Code
|
v
Execute Selenium Tests
|
v
Generate Test Results</code></pre>
<hr>
<h2>35. Verify Selenium Dependency</h2>
<p>The Maven dependency tree can be used to verify how Selenium and related artifacts have been resolved.</p>
<pre><code>mvn dependency:tree</code></pre>
<p>This command is especially useful when troubleshooting dependency conflicts.</p>
<hr>
<h2>36. Maven Dependency Tree Example</h2>
<pre><code>mvn dependency:tree
Project
|
+-- org.seleniumhq.selenium:selenium-java
| |
| +-- Selenium API
| +-- Browser Driver Components
| +-- Remote Driver Components
| +-- Selenium Support
|
+-- TestNG / JUnit</code></pre>
<p>The exact dependency tree depends on the selected Selenium version and the other dependencies in the project.</p>
<hr>
<h2>37. Updating Selenium Version</h2>
<p>To update Selenium, change the version in <strong>pom.xml</strong> and reload the Maven project.</p>
<pre><code><selenium.version>NEW_VERSION</selenium.version></code></pre>
<p>For example:</p>
<pre><code><properties>
<selenium.version>NEW_VERSION</selenium.version>
</properties></code></pre>
<p>After changing the version, run:</p>
<pre><code>mvn clean test</code></pre>
<hr>
<h2>38. Selenium Version Compatibility</h2>
<p>When upgrading Selenium, compatibility should be considered across the complete automation environment.</p>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Component</th><th>What to Check</th></tr>
<tr><td>Java</td><td>Supported Java version for the selected Selenium release.</td></tr>
<tr><td>Selenium</td><td>Selected Selenium Java version.</td></tr>
<tr><td>Browser</td><td>Installed browser version and behavior.</td></tr>
<tr><td>Test Framework</td><td>TestNG or JUnit compatibility.</td></tr>
<tr><td>Maven</td><td>Build configuration and plugins.</td></tr>
<tr><td>CI/CD</td><td>JDK, Maven, browser, and execution environment.</td></tr>
</table>
<hr>
<h2>39. Selenium Java Dependency and Java Version</h2>
<p>Selenium Java projects require a compatible Java runtime. When selecting or upgrading Selenium, verify the Java requirements for the chosen Selenium release.</p>
<p>Do not assume that every Selenium release supports every Java version. Compatibility should be checked before upgrading a production automation framework.</p>
<hr>
<h2>40. Selenium Dependency in IntelliJ IDEA</h2>
<ol>
<li>Create a Maven project.</li>
<li>Open pom.xml.</li>
<li>Add the selenium-java dependency.</li>
<li>Save pom.xml.</li>
<li>Allow IntelliJ IDEA to reload Maven changes.</li>
<li>Open the Maven tool window if required.</li>
<li>Run the Selenium test.</li>
</ol>
<hr>
<h2>41. Selenium Dependency in Eclipse</h2>
<ol>
<li>Create a Maven project.</li>
<li>Open pom.xml.</li>
<li>Add the selenium-java dependency.</li>
<li>Save the file.</li>
<li>Update Maven project configuration.</li>
<li>Verify Selenium dependencies under Maven Dependencies.</li>
<li>Create and execute the Selenium Java test.</li>
</ol>
<hr>
<h2>42. Common Error: WebDriver Cannot Be Resolved</h2>
<p>If the IDE reports that <strong>WebDriver cannot be resolved</strong>, verify whether the Selenium dependency has been added correctly.</p>
<pre><code>import org.openqa.selenium.WebDriver;</code></pre>
<p>Check the following:</p>
<ul>
<li>selenium-java exists in pom.xml.</li>
<li>The dependency version is valid.</li>
<li>Maven project synchronization has completed.</li>
<li>The required artifacts are available in the local repository.</li>
<li>The project has no dependency resolution errors.</li>
</ul>
<hr>
<h2>43. Common Error: ChromeDriver Cannot Be Resolved</h2>
<p>If ChromeDriver cannot be resolved by the IDE, verify the Selenium dependency and Maven synchronization.</p>
<pre><code>import org.openqa.selenium.chrome.ChromeDriver;</code></pre>
<p>Also verify that the project is using a valid Selenium version and that Maven has successfully resolved its dependencies.</p>
<hr>
<h2>44. Common Error: Dependency Not Downloaded</h2>
<p>If Maven cannot download Selenium, possible causes include:</p>
<ul>
<li>Incorrect groupId.</li>
<li>Incorrect artifactId.</li>
<li>Invalid version.</li>
<li>Network connectivity issue.</li>
<li>Repository configuration problem.</li>
<li>Proxy configuration issue.</li>
<li>Corrupted local Maven cache.</li>
</ul>
<h3>Correct Coordinates</h3>
<pre><code>groupId:
org.seleniumhq.selenium
artifactId:
selenium-java</code></pre>
<hr>
<h2>45. Common Error: Wrong Selenium Version</h2>
<p>A project may fail after a dependency upgrade if the selected Selenium version is incompatible with the project's Java environment or another part of the framework.</p>
<p>Before upgrading:</p>
<ol>
<li>Check the Selenium release information.</li>
<li>Check supported Java versions.</li>
<li>Check test framework compatibility.</li>
<li>Run the complete regression suite.</li>
<li>Review dependency conflicts.</li>
</ol>
<hr>
<h2>46. Common Error: Maven Dependency Conflict</h2>
<p>Dependency conflicts can occur when different libraries require different versions of the same artifact.</p>
<p>Use the following command to investigate the resolved dependency hierarchy:</p>
<pre><code>mvn dependency:tree</code></pre>
<p>The dependency tree can help identify which library introduced a particular dependency and which version Maven selected.</p>
<hr>
<h2>47. Excluding a Transitive Dependency</h2>
<p>In advanced Maven projects, an unwanted transitive dependency can sometimes be excluded.</p>
<pre><code><dependency>
<groupId>example.group</groupId>
<artifactId>example-artifact</artifactId>
<version>EXAMPLE_VERSION</version>
<exclusions>
<exclusion>
<groupId>example.group</groupId>
<artifactId>example-library</artifactId>
</exclusion>
</exclusions>
</dependency></code></pre>
<p>Exclusions should be used carefully because removing a required dependency can cause compilation or runtime failures.</p>
<hr>
<h2>48. Direct vs Transitive Dependency</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Direct Dependency</th><th>Transitive Dependency</th></tr>
<tr><td>Explicitly declared in pom.xml.</td><td>Required by another dependency.</td></tr>
<tr><td>Directly requested by the project.</td><td>Resolved through dependency relationships.</td></tr>
<tr><td>Example: selenium-java.</td><td>Supporting Selenium components.</td></tr>
</table>
<hr>
<h2>49. Selenium Dependency and Page Object Framework</h2>
<pre><code>selenium-java
|
v
WebDriver API
|
+-- BaseTest
|
+-- Page Objects
|
+-- Utilities
|
+-- Test Classes
|
v
TestNG / JUnit
|
v
Maven
|
v
CI/CD</code></pre>
<hr>
<h2>50. Practical Project: Selenium Login Automation</h2>
<p>Create a Maven project that automates a login page.</p>
<h3>Step 1: Add Dependency</h3>
<pre><code><dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>YOUR_SELENIUM_VERSION</version>
</dependency></code></pre>
<h3>Step 2: Create Test</h3>
<pre><code>import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoginTest {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
System.out.println("Title: " + driver.getTitle());
} finally {
driver.quit();
}
}
}</code></pre>
<hr>
<h2>51. Practical Project Structure</h2>
<pre><code>selenium-login/
|
|-- pom.xml
|
|-- src/
| |
| |-- test/
| |
| |-- java/
| |
| |-- tests/
| |-- LoginTest.java
|
|-- target/</code></pre>
<hr>
<h2>52. Practical Project: Selenium + TestNG + Maven</h2>
<p>A professional Selenium automation project commonly combines the Selenium dependency with a test framework and supporting framework components.</p>
<pre><code>Java
|
+-- Selenium WebDriver
|
+-- TestNG
|
+-- Maven
|
+-- Page Object Model
|
+-- Utilities
|
+-- Test Data
|
+-- Reports
|
+-- CI/CD</code></pre>
<hr>
<h2>53. Selenium Dependency and CI/CD</h2>
<p>Maven helps make Selenium dependencies reproducible in CI environments because the project's dependency configuration is stored in <strong>pom.xml</strong>.</p>
<pre><code>Developer
|
v
Git Repository
|
v
CI Server
|
v
pom.xml
|
v
Resolve Selenium Dependency
|
v
Compile
|
v
Run Selenium Tests
|
v
Reports</code></pre>
<hr>
<h2>54. Selenium Dependency and Jenkins</h2>
<p>A Jenkins job can execute Maven commands such as:</p>
<pre><code>mvn clean test</code></pre>
<p>The CI server uses the project's Maven configuration to resolve dependencies and execute the configured test lifecycle.</p>
<hr>
<h2>55. Selenium Dependency and Git</h2>
<p>The Selenium dependency configuration should be stored in <strong>pom.xml</strong> and committed to source control.</p>
<p>Individual Selenium JAR files generally should not be manually committed into the project when Maven is being used for dependency management.</p>
<h3>Example</h3>
<pre><code>Git Repository
|
+-- pom.xml
+-- src/
+-- README.md
+-- .gitignore</code></pre>
<hr>
<h2>56. Recommended Maven Project Files</h2>
<pre><code>selenium-framework/
|
+-- pom.xml
+-- README.md
+-- .gitignore
|
+-- src/
+-- main/
+-- test/</code></pre>
<hr>
<h2>57. Selenium Dependency Best Practices</h2>
<ul>
<li>Use Maven instead of manually managing Selenium JAR files.</li>
<li>Keep the Selenium version explicitly controlled.</li>
<li>Use Maven properties when the version is referenced in multiple places.</li>
<li>Use a version compatible with the project's Java runtime.</li>
<li>Check release information before upgrading Selenium.</li>
<li>Run the complete test suite after a dependency upgrade.</li>
<li>Use <strong>mvn dependency:tree</strong> when troubleshooting dependency conflicts.</li>
<li>Avoid unnecessary Selenium component declarations.</li>
<li>Keep pom.xml clean and readable.</li>
<li>Use CI/CD to validate dependency and framework changes.</li>
</ul>
<hr>
<h2>58. Common Mistakes</h2>
<ul>
<li>Typing the Selenium groupId incorrectly.</li>
<li>Typing the artifactId incorrectly.</li>
<li>Using an invalid Selenium version.</li>
<li>Forgetting to reload the Maven project.</li>
<li>Downloading JAR files manually while also using Maven.</li>
<li>Ignoring Java and Selenium compatibility.</li>
<li>Not checking dependency conflicts.</li>
<li>Adding duplicate Selenium dependencies unnecessarily.</li>
<li>Using outdated dependency versions without a project requirement.</li>
<li>Skipping regression tests after dependency upgrades.</li>
</ul>
<hr>
<h2>59. Selenium Java Dependency Interview Questions</h2>
<h3>Q1. What is Selenium Java dependency?</h3>
<p>It is a Maven dependency that provides Selenium WebDriver libraries and related components to a Java automation project.</p>
<h3>Q2. What is the groupId of Selenium Java?</h3>
<p>The groupId is <strong>org.seleniumhq.selenium</strong>.</p>
<h3>Q3. What is the artifactId?</h3>
<p>The commonly used artifactId is <strong>selenium-java</strong>.</p>
<h3>Q4. Where is the Selenium dependency configured?</h3>
<p>It is configured in the project's <strong>pom.xml</strong> file when Maven is used.</p>
<h3>Q5. Why use Maven for Selenium?</h3>
<p>Maven manages Selenium libraries, dependency versions, transitive dependencies, project builds, test execution, and CI/CD integration.</p>
<h3>Q6. What is the Selenium Maven dependency syntax?</h3>
<pre><code><dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>YOUR_SELENIUM_VERSION</version>
</dependency></code></pre>
<h3>Q7. What happens when Maven downloads Selenium?</h3>
<p>Maven resolves the requested Selenium artifact and its required dependencies, stores them in the local repository, and makes them available to the project.</p>
<h3>Q8. What is a transitive dependency?</h3>
<p>A transitive dependency is a library required by another dependency and resolved through Maven's dependency management.</p>
<h3>Q9. How do you check Selenium dependency resolution?</h3>
<pre><code>mvn dependency:tree</code></pre>
<h3>Q10. How do you update Selenium?</h3>
<p>Change the Selenium version in pom.xml, reload the Maven project, and execute the project's tests.</p>
<h3>Q11. Can Selenium Java be used without Maven?</h3>
<p>Yes. Selenium Java can be used with other build tools or manually managed JAR files, but Maven simplifies dependency management for Java projects.</p>
<h3>Q12. What is selenium-java?</h3>
<p>selenium-java is the Maven artifact commonly used to bring Selenium's Java client and required Selenium components into a Maven project.</p>
<hr>
<h2>60. Quick Revision</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Concept</th><th>Key Point</th></tr>
<tr><td>Selenium Java</td><td>Java library for Selenium browser automation.</td></tr>
<tr><td>Maven</td><td>Build and dependency management tool.</td></tr>
<tr><td>pom.xml</td><td>Central Maven project configuration file.</td></tr>
<tr><td>groupId</td><td>org.seleniumhq.selenium</td></tr>
<tr><td>artifactId</td><td>selenium-java</td></tr>
<tr><td>version</td><td>Selected Selenium release.</td></tr>
<tr><td>Repository</td><td>Source from which Maven obtains artifacts.</td></tr>
<tr><td>Local Repository</td><td>Stores downloaded Maven artifacts locally.</td></tr>
<tr><td>Transitive Dependency</td><td>Dependency required by another dependency.</td></tr>
<tr><td>dependency:tree</td><td>Displays the dependency hierarchy.</td></tr>
<tr><td>TestNG</td><td>Popular test framework used with Selenium.</td></tr>
<tr><td>JUnit</td><td>Another test framework commonly used with Selenium.</td></tr>
</table>
<hr>
<h2>61. Important Maven Commands</h2>
<pre><code>mvn -version
mvn clean
mvn compile
mvn test
mvn clean test
mvn package
mvn dependency:tree
mvn help:effective-pom</code></pre>
<hr>
<h2>62. Complete Selenium Dependency Flow</h2>
<pre><code>Java Selenium Project
|
v
pom.xml
|
v
org.seleniumhq.selenium
|
v
selenium-java
|
v
Resolve Selenium Components
|
v
Download / Cache Artifacts
|
v
Local Maven Repository
|
v
Java Classpath
|
v
WebDriver APIs
|
v
Browser Automation
|
v
TestNG / JUnit
|
v
Maven Test Execution
|
v
Reports / CI-CD</code></pre>
<hr>
<h2>63. Final Summary</h2>
<p><strong>Selenium Java Dependency</strong> is a fundamental part of a Maven-based Selenium automation framework. By declaring <strong>org.seleniumhq.selenium:selenium-java</strong> in pom.xml, a Java project can obtain Selenium APIs and required Selenium components through Maven dependency management.</p>
<p>The most important concepts to understand are <strong>groupId, artifactId, version, pom.xml, Maven repositories, local repository, transitive dependencies, dependency scopes, Selenium browser components, TestNG/JUnit integration, dependency:tree, version management, and CI/CD integration</strong>.</p>
<p>A Selenium tester who understands Maven dependencies can create cleaner, reproducible, maintainable, and CI/CD-ready Java automation frameworks.</p>
<hr>
<h2>64. Course Resources</h2>
<p><strong>Selenium Training:</strong> <a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">https://www.justacademy.co/course-detail/selenium-training</a></p>
<p><strong>Register for Course Demo:</strong> <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">https://www.justacademy.co/register-for-course-demo</a></p>
</div>